package com.autonavi.yunda.yunji.core.vo.response;

import com.autonavi.yunda.yunji.core.model.dto.ProjectDTO;
import com.autonavi.yunda.yunji.core.model.dto.TaskConfigDTO;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author sunzhenbang
 */
@Data
public class TaskConfigPageVO {
    private List<SimpleTaskConfigVO> list;
    private Long total;

    public TaskConfigPageVO() {
        this.list = new ArrayList<>();
        this.total = 0L;
    }

    public TaskConfigPageVO(List<TaskConfigDTO> list, List<ProjectDTO> projectDTOS, long total) {
        Map<String, String> projectIdNameMap = projectDTOS.stream().collect(Collectors.toMap(ProjectDTO::getProjectId, ProjectDTO::getName));
        this.list = list.stream().map(dto -> SimpleTaskConfigVO.from(dto, projectIdNameMap.get(dto.getProjectId()))).collect(Collectors.toList());
        this.total = total;
    }
}
